import { ref, watch, watchEffect } from "vue"
import type { BaseWidgetType, DesignerType } from "../type"

export const useCreateDesigner = ():DesignerType=>{
    const widgets = ref<BaseWidgetType[]>([])
    const curWidget = ref<BaseWidgetType | null>(null)

    const selectCurWidget = (widget:any)=>{
        curWidget.value = widget
    }
    const deleteWidget = (widget:any)=>{
        const index = widgets.value.findIndex(i=>i.id == widget.id)
        if(index != -1) widgets.value.splice(index,1)
    }
    return {
        widgets,
        curWidget,
        selectCurWidget,
        deleteWidget
    }
}